#!/bin/sh
set -e

TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"
setupenvironment
configarchitecture 'amd64'

insertpackage 'unstable' 'runit-init' 'all' '1' 'Conflicts: systemd-sysv, sysvinit-core, runit-init'
# note how the rest do not know of runit-init
insertpackage 'unstable' 'sysvinit-core' 'all' '1' 'Conflicts: systemd-sysv, sysvinit-core'
insertpackage 'unstable,installed' 'systemd-sysv' 'all' '1' 'Conflicts: systemd-sysv, sysvinit-core'
insertpackage 'unstable,installed' 'init' 'all' '1' 'Pre-Depends: systemd-sysv | sysvinit-core
Important: yes'

setupaptarchive

testsuccessequal "Reading package lists...
Building dependency tree...
   Removing: systemd-sysv:amd64 as upgrade is not an option for runit-init:amd64 (1)
    MarkDelete systemd-sysv:amd64 < 1 @ii K > FU=0
  MarkInstall runit-init:amd64 < none -> 1 @un puN > FU=1
Starting pkgProblemResolver with broken count: 1
Starting 2 pkgProblemResolver with broken count: 1
Investigating (0) init:amd64 < 1 @ii K Ib >
Broken init:amd64 PreDepends on systemd-sysv:amd64 < 1 @ii pR >
  Considering systemd-sysv:amd64 0 as a solution to init:amd64 5100
  Added systemd-sysv:amd64 to the remove list
Broken init:amd64 PreDepends on sysvinit-core:amd64 < none @un pH >
  Considering sysvinit-core:amd64 0 as a solution to init:amd64 5100
  Ignore MarkKeep of systemd-sysv:amd64 < 1 @ii pR > as its mode (Delete) is protected
Investigating (1) init:amd64 < 1 @ii K Ib >
Broken init:amd64 PreDepends on systemd-sysv:amd64 < 1 @ii pR >
  Considering systemd-sysv:amd64 5100 as a solution to init:amd64 5100
Broken init:amd64 PreDepends on sysvinit-core:amd64 < none @un pH >
  Considering sysvinit-core:amd64 0 as a solution to init:amd64 5100
  Or group remove for init:amd64
  MarkDelete init:amd64 < 1 @ii K Ib > FU=0
Done
The following packages will be REMOVED:
  init systemd-sysv
The following NEW packages will be installed:
  runit-init
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  init systemd-sysv (due to init)
  MarkDelete init:amd64 < 1 @ii K > FU=1
0 upgraded, 1 newly installed, 2 to remove and 0 not upgraded.
Remv init [1]
  MarkDelete systemd-sysv:amd64 < 1 | none @ii H > FU=1
Remv systemd-sysv [1]
Inst runit-init (1 unstable [all])
Conf runit-init (1 unstable [all])" apt install runit-init -so Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::Marker=1 -o Debug::pkgDepCache::AutoInstall=1 -o APT::Get::Allow-Solver-Remove-Essential=1
